<%
/*
* Duoc chinh sua boi : Pham Thanh vao ngay 24/9/2013
*/
%>
<%@page import="DAO.LoginDAO"%>
<%@page import="Entity.Users"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
    Users user = null;
    String userName = "^_^";
    String exeption = "Exception: No";
    int n = 0;
    try{    	
        user = (Users)session.getAttribute("userSession");
        if(user != null){
    	    response.sendRedirect("homepage.jsp");
        }else{
            //response.sendRedirect("homepage.jsp");
            Cookie [] cookies = request.getCookies();
            n = cookies.length;
            if(n>0){
                for(int i=0; i<n; i++){
    	        	if(cookies[i].getName().equals("c_u")){
    	        		userName = cookies[i].getValue();
    	        		user = LoginDAO.getUsers(userName);
    	        		session.setAttribute("userSession", user);
    	        		
                	}    	        	
    	        }    	    
            }
            if(user != null){
        	    response.sendRedirect("homepage.jsp");
            }            
        } 
    
    }catch(Exception ex){
        exeption = "Exeption: "+ex.getMessage();
    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="headtag.jsp" />
<title> Service Directory </title>
</head>

<body>
<div id="headWrap">
 <div id="headpanel">
  <jsp:include page="header.jsp" />
 </div>
</div>
<div id="contentWrap">
 <div id="contentPanel">
  <div id="loginWraper">
   <div id="login">
    <form name="formLogin" action="login" method="post">
     <table>
      <tr>
       <td> Username </td>
       <td> <input name="username" type="text" size="26" /></td>
      </tr>
      <tr>
       <td> Password </td>
       <td> <input name="password" type="password" size="26" /></td>
      </tr>     
      <tr>
       <td> </td>
       <td> 
        <input type="checkbox" name="rememberLogin" value="rememberlogin" /> 
        Remember me
        <input type="submit" name="submit" value="Login"  /> </td>
      </tr>
      <tr>
       <td> <%=userName %>  </td>
       <td> <a href="#"> Forgot password ! </a> </td>
      </tr>
     </table>
     <s:actionmessage />
    </form>
    <%=exeption+"\n"  %>
    <%=user+"\n" %>
    <%="n = "+n+"\n" %>
   </div>
  </div>
 </div>
</div>
<div id="footWrap">
 <div id="footPanel">
  <jsp:include page="footer.jsp" />
 </div>
</div>
</body>
</html>
